package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarGasoline;
import com.ruoyi.car.service.ICarGasolineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加油Controller
 * 
 * @author ruoyi
 * @date 2022-12-03
 */
@RestController
@RequestMapping("/car/gasoline")
public class CarGasolineController extends BaseController
{
    @Autowired
    private ICarGasolineService carGasolineService;

    /**
     * 查询加油列表
     */
    @PreAuthorize("@ss.hasPermi('car:gasoline:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarGasoline carGasoline)
    {
        startPage();
        List<CarGasoline> list = carGasolineService.selectCarGasolineList(carGasoline);
        return getDataTable(list);
    }

    /**
     * 导出加油列表
     */
    @PreAuthorize("@ss.hasPermi('car:gasoline:export')")
    @Log(title = "加油", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarGasoline carGasoline)
    {
        List<CarGasoline> list = carGasolineService.selectCarGasolineList(carGasoline);
        ExcelUtil<CarGasoline> util = new ExcelUtil<CarGasoline>(CarGasoline.class);
        util.exportExcel(response, list, "加油数据");
    }

    /**
     * 获取加油详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:gasoline:query')")
    @GetMapping(value = "/{gasolineId}")
    public AjaxResult getInfo(@PathVariable("gasolineId") Long gasolineId)
    {
        return success(carGasolineService.selectCarGasolineByGasolineId(gasolineId));
    }

    /**
     * 新增加油
     */
    @PreAuthorize("@ss.hasPermi('car:gasoline:add')")
    @Log(title = "加油", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarGasoline carGasoline)
    {
        return toAjax(carGasolineService.insertCarGasoline(carGasoline));
    }

    /**
     * 修改加油
     */
    @PreAuthorize("@ss.hasPermi('car:gasoline:edit')")
    @Log(title = "加油", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarGasoline carGasoline)
    {
        return toAjax(carGasolineService.updateCarGasoline(carGasoline));
    }

    /**
     * 删除加油
     */
    @PreAuthorize("@ss.hasPermi('car:gasoline:remove')")
    @Log(title = "加油", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gasolineIds}")
    public AjaxResult remove(@PathVariable Long[] gasolineIds)
    {
        return toAjax(carGasolineService.deleteCarGasolineByGasolineIds(gasolineIds));
    }
}
